Expression Problem
Philip Wadlerが作った言葉らしい
静的型付き言語で、再コンパイルなしで、新しいデータ型を追加したり、新しい関数を追加できるようにするにはどうしたらよいか、という問題
出典
The Expression Problem is a new name for an old problem. The goal is to define a datatype by cases, where one can add new cases to the datatype and new functions over the datatype, without recompiling existing code, and while retaining static type safety (e.g., no casts). ref
関数型とOOPの対比で言及されることが多い
関数型の短所、OOPの長所として言及される
基本のデータ型とそれに対する関数などが定義されている状態で、後にそのデータ型に機能を追加したいとなったとき
関数型の場合は、データ型に1つ追加するだけで、広い範囲に手を加える必要があるので、全体を再コンパイルしないといけない
OOPの場合は、一つのclassに収まっているので、propertyを追加すること自体はかんたん
一方でmethodを追加することは大変
振る舞い駆動だからねmrsekut.icon
解答
型クラスが1つの解決策になる
Data Types a la Carte
Tagless final
Polymorphic Variant
感想
別に型エラーでるんだから、散らばっていても良くないか?と思ったりしてしまうmrsekut.icon
再コンパイルに対するコストの大きさを感じていないからだろうか
問題を問題と感じられないので、ちょっと保留しようmrsekut.icon
参考
The Expression Problem - maoeのブログ
具体例もあってわかりやすい
https://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Dr-Ralf-Laemmel-Advanced-Functional-Programming-The-Expression-Problem
https://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Dr-Ralf-Lmmel-Advanced-Functional-Programming-Type-Classes'
FunctionalDependencies
Scalaのimplict conversion
http://okmij.org/ftp/tagless-final/course/index.html
https://zehnpaard.hatenablog.com/entry/2021/03/23/234703
この問題に対して、「OOP vs 関数型」な論はかなり雑じゃないか?という考察
https://camlspotter.hatenablog.com/entry/20121216/1355686499
https://eli.thegreenplace.net/2018/more-thoughts-on-the-expression-problem-in-haskell/
https://eli.thegreenplace.net/2016/the-expression-problem-and-its-solutions/
https://cylomw.hatenablog.com/entry/2019/10/15/140900